package concurrent.collection;

import org.junit.Test;

import java.util.Hashtable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.IntStream;

public class ConcurrentHashMapTest {

	@Test
	public void concurrentHashMap() {

		ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>();

		long start = System.currentTimeMillis();
		IntStream.rangeClosed(1, 10).parallel().forEach(item -> {
			for (int i = 0; i < 10_000_000; i++) {
				map.put(i, i);
			}
		});
		System.out.println(System.currentTimeMillis() - start);
	}

	@Test
	public void hashTable() {

		Hashtable<Integer, Integer> map = new Hashtable<>();

		long start = System.currentTimeMillis();
		IntStream.rangeClosed(1, 10).parallel().forEach(item -> {
			for (int i = 0; i < 10_000_000; i++) {
				map.put(i, i);
			}
		});
		System.out.println(System.currentTimeMillis() - start);
	}
}
